/** 
 * 2011-10-11 上午11:10:33 
 * UdpMessageDispatcher.java 
 * author:sunb 
 */
package com.u6.udp.netty;

import org.jboss.netty.channel.MessageEvent;

import com.lamfire.utils.ObjectFactory;

/**
 * @author sunbin
 * 
 */
public class UdpMessageDispatcher {

	public void dispatch(UdpMessage message,MessageEvent event) {
		try {
			short messageID = message.getMessageID();
			Class<UdpAction> clazz = UdpMessageActionClassMap.getInstance().lookupRegisteredReapeater(messageID);

			if (clazz == null) {

				return;
			}

			UdpMessageContext.newInstance(message);
			ObjectFactory factory = new ObjectFactory(clazz);

			UdpAction action = (UdpAction) factory.newInstance();

			if (action == null) {
				return;
			}
			action.execute(event);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
